/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package langen;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

/**
 *
 * @author s0920761
 */
public class TemplateGe_Library extends TemplateLanguageGenerator{

       private ArrayList <SentenceTemplate> sentenceList  = new ArrayList <SentenceTemplate> ();
       private HashMap keywords=new HashMap();

       public TemplateGe_Library(){
           populateSentences();
           populatekeywords();

       }
    
    private void populateSentences() {
        /*add sentences to sentencetemplate*/
       sentenceList.add(new SentenceTemplate("question","do you like my book %NOUN%?"));
       sentenceList.add(new SentenceTemplate("reply","you are a very good reader, my new book %NOUN% & %NOUN% will come soon."));
    
       
       sentenceList.add(new SentenceTemplate("question","How about change a topic, who is your favourite writer?"));
        
    }
    private void populatekeywords(){
       
       keywords.put("buy", "thank you for your support");
       keywords.put("it is", "It is worth reading");
       keywords.put("friend", "i am not sure about your friend, Do you like my book? don't be shy, have a try");
       keywords.put("hello", "hello, welcome to you, enjoy yourself");
       keywords.put("know", "I am very very busy");
       keywords.put("where", "Edinburgh is a very beautiful city");
       keywords.put("I", "Your friend just left, what a pity!");
       keywords.put("you", "Thank you. The same to you");
        
    }

    private String keyWordMatch(String remark){
       remark=this.stip(remark.toLowerCase());

       String[] words=remark.split(" ");
       String s;
       for(String word: words){
           if(keywords.containsKey(word))
           {
               return (String) keywords.get(word);
           }

       }


            s=this.findKeyWord(remark);
            return super.expandTemplateTopic(s,sentenceList.get(P.nextInt(sentenceList.size())).getTemplate());

    }

     public String generateReply(String remark) {
        String keyword;
        keyword=super.findKeyWord(remark);
        Random s=new Random();


        if(P.nextBoolean()&&s.nextBoolean())
        
        return super.expandTemplateTopic(keyword,sentenceList.get(P.nextInt(sentenceList.size())).getTemplate());//if i==0 use expendtemplatetopic
        else
        {
            return this.keyWordMatch(remark);//i==1 use keywrodmatch
        }
}
public static void main(String[] args) {
		TemplateGe_Library s=new TemplateGe_Library();
                while(true)
                {
                System.out.println(s.generateReply("buy"));
                }

	}

}
